//promise
//图片加载，获取到图片后的处理
function LoadImg(){
    return new Promise((resolve,reject)=>{
        const img = new Image();
        img.onload = function(){
            resolve(img)
        };
        img.onerror = function(){
            reject('error')
        };
    })
};
LoadImg.then(res=>{
    console.log(res);
})

//promise.all()和promise.race()
//如何同时触发多个promise，用于处理并发任务，多个异步都结束再执行下一个任务
let p1 = new Promise((resolve,reject)=>{
    resolve('第一个异步结果')
});
let p2 = new Promise((resolve,reject)=>{
    resolve('第二个异步结果')
});
let p3 = new Promise((resolve,reject)=>{
    resolve('第三个异步结果')
});
Promise.all([p1,p2,p3]).then(arr=>{
    console.log(arr);
})